package org.blogwu.hyf.sso.main.control;

import java.util.HashMap;
import java.util.Map;

import org.blogwu.hyf.sso.main.bean.generalbean.LoginUser;
import org.blogwu.hyf.sso.main.until.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController extends BasisContorl{

/*	private final Logger logger = LoggerFactory.getLogger(LoginController.class);

	@Autowired
	private DiscoveryClient client;//获取客户端信息
*/

	@RequestMapping(value = "/test" ,method = RequestMethod.GET)
	public Integer test(@RequestParam Integer a, @RequestParam Integer b) {
		ServiceInstance instance = client.getLocalServiceInstance();
		Integer r = a + b;
		logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r);
		return r;
	}

	/**
	 * 
	 * @Title: userLogin
	 * @Description: 登录
	 * @param @param loginUser
	 * @param @return    参数
	 * @return Integer    返回类型
	 * @throws
	 */
	@RequestMapping(value = "/login" ,method = RequestMethod.POST)
	public void userLogin(LoginUser loginUser) {
		Map<String, Object> result=new HashMap<String, Object>();

	
		System.out.println(loginUser.getUsername()+"---"+loginUser.getPassword());
		if(!checkParms(loginUser)){
			result.put("status", 400);
			result.put("message", "用户名密码不能为空");
		}
		
		ServiceInstance instance = client.getLocalServiceInstance();
		logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId());

	}


	/**
	 * 
	 * @Title: checkParms
	 * @Description: 检查参数是否为空   true 为 为空   false  为参数不为空
	 * @param @param loginUser
	 * @param @return    参数
	 * @return boolean    返回类型
	 * @throws
	 */
	private boolean checkParms(LoginUser loginUser){
		return StringUtils.isBlank(loginUser.getUsername(),loginUser.getPassword());
	}

}
